import { createStore, useStore as baseUserStore } from 'vuex'
import users from './modules/users'

import type { UsersState } from './modules/users'

import type { Store } from 'vuex'
import VuexPersistence from 'vuex-persist'
import type { InjectionKey } from 'vue'

export interface State {

}

export interface StateAll extends State {
  users: UsersState
}

const VuexLocal = new VuexPersistence<State>({
  storage: window.localStorage,
  reducer: (state) => ({
    users: {
      infos: (state as StateAll).users.infos,
    }
  })
})

export const key: InjectionKey<Store<StateAll>> = Symbol()

export function useStore() {
  return baseUserStore(key)
}

export default createStore({
  state: {
  },
  getters: {
  },
  mutations: {
  },
  actions: {
  },
  modules: {
    users,
  },
  plugins: [VuexLocal.plugin]
})
